﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Modularity;
using WPFStudy.PrismStudy.ModuleStudyA;
using WPFStudy.PrismStudy.ModuleStudyB;
using WPFStudy.PrismStudy.Views;

namespace WPFStudy.PrismStudy
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>

    //public partial class App : Application
    //变更父类为 Prism.DryIoc.PrismApplication
    public partial class App : PrismApplication

    {
        protected override void InitializeShell(Window shell)
        {
            //制作登录页，先登录成功，再初始化WindowShell
            //LoginView loginView = new LoginView();
            //if (loginView.ShowDialog() == true)
            //{
            //    var shellVM = shell.DataContext as MainWindowViewModel;
            //    shellVM.InitData();
            //    base.InitializeShell(shell);
            //}
            //else
            //{
            //    Application.Current.Shutdown(-1);
            //}
        }

        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
            //throw new NotImplementedException();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.Register<RegionStudyView>();
            containerRegistry.Register<ContentControlViewA>();
            containerRegistry.RegisterForNavigation<ContentControlViewA>();
            containerRegistry.RegisterForNavigation<ContentControlViewB>();
            containerRegistry.RegisterForNavigation<ContentControlViewC>();
            containerRegistry.RegisterForNavigation<NavigateAView>();
            containerRegistry.RegisterForNavigation<NavigateBView>();

            //注册对话控件
            containerRegistry.RegisterDialog<DialogShowView>();
            //throw new NotImplementedException();
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            moduleCatalog.AddModule<Module>();
            #region 添加模块 5种方式，参考文档：https://github.com/PrismLibrary/Prism-Samples-Wpf 07-Modules
            //5种方式：AppConfig、Code、Directory、LoadManual、Xaml


            //方式1：通过代码引用的方式
            moduleCatalog.AddModule<ModuleAProfile>();
            moduleCatalog.AddModule<ModuleBProfile>();

            //方式2：通过文件加载的方式,配置读取文件夹
            #endregion
            base.ConfigureModuleCatalog(moduleCatalog);
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            //添加模块 方式2：通过文件加载的方式,配置读取文件夹,必须在当前项目的编译结果目录创建Modules目录，否则允许会报错。
            //在项目WPFStudy.PrismStudy.ModuleStudyA的项目属性中，设置了生成相关的命令，配置路径：项目属性->生成->事件->生成后事件添加bat命令：
            //xcopy "$(TargetDir)$(TargetName)*$(TargetExt)" "$(SolutionDir)\WPFStudy.PrismStudy\bin\Debug\net6.0-windows\Modules\" /Y /S
            //将在WPFStudy.PrismStudy.ModuleStudyA项目生成成功后，将生成的目录copy至指定的目录中  
            return new DirectoryModuleCatalog()
            {
                //当前目录下的Modules目录的所有实现IModule类的类库
                ModulePath = @".\Modules",                
            };
            //return base.CreateModuleCatalog();
        }
    }
}
